home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / troubleshoot / base.py < prev    next >
Text File  |  2009-10-19  |  3KB  |  103 lines

  1. #!/usr/bin/env python
  2.  
  3. ## Printing troubleshooter
  4.  
  5. ## Copyright (C) 2008 Red Hat, Inc.
  6. ## Copyright (C) 2008 Tim Waugh <twaugh@redhat.com>
  7.  
  8. ## This program is free software; you can redistribute it and/or modify
  9. ## it under the terms of the GNU General Public License as published by
  10. ## the Free Software Foundation; either version 2 of the License, or
  11. ## (at your option) any later version.
  12.  
  13. ## This program is distributed in the hope that it will be useful,
  14. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ## GNU General Public License for more details.
  17.  
  18. ## You should have received a copy of the GNU General Public License
  19. ## along with this program; if not, write to the Free Software
  20. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. import gtk
  23. from gettext import gettext as _
  24. from debug import *
  25.  
  26. __all__ = [ 'gtk',
  27.             '_',
  28.             'debugprint', 'get_debugging', 'set_debugging',
  29.             'Question',
  30.             'Multichoice',
  31.             'TEXT_start_print_admin_tool' ]
  32.  
  33. TEXT_start_print_admin_tool = _("To start this tool, select "
  34.                                 "System->Administration->Printing "
  35.                                 "from the main menu.")
  36.  
  37. class Question:
  38.     def __init__ (self, troubleshooter, name=None):
  39.         self.troubleshooter = troubleshooter
  40.         if name:
  41.             self.__str__ = lambda: name
  42.  
  43.     def display (self):
  44.         """Returns True if this page should be displayed, or False
  45.         if it should be skipped."""
  46.         return True
  47.  
  48.     def connect_signals (self, handler):
  49.         pass
  50.  
  51.     def disconnect_signals (self):
  52.         pass
  53.  
  54.     def can_click_forward (self):
  55.         return True
  56.  
  57.     def collect_answer (self):
  58.         return {}
  59.  
  60.     def cancel_operation (self):
  61.         pass
  62.  
  63.     ## Helper functions
  64.     def initial_vbox (self, title='', text=''):
  65.         vbox = gtk.VBox ()
  66.         vbox.set_border_width (12)
  67.         vbox.set_spacing (12)
  68.         if title:
  69.             s = '<span weight="bold" size="larger">' + title + '</span>\n\n'
  70.         else:
  71.             s = ''
  72.         s += text
  73.         label = gtk.Label (s)
  74.         label.set_alignment (0, 0)
  75.         label.set_line_wrap (True)
  76.         label.set_use_markup (True)
  77.         vbox.pack_start (label, False, False, 0)
  78.         return vbox
  79.  
  80. class Multichoice(Question):
  81.     def __init__ (self, troubleshooter, question_tag, question_title,
  82.                   question_text, choices, name=None):
  83.         Question.__init__ (self, troubleshooter, name)
  84.         page = self.initial_vbox (question_title, question_text)
  85.         choice_vbox = gtk.VBox ()
  86.         choice_vbox.set_spacing (6)
  87.         page.pack_start (choice_vbox, False, False, 0)
  88.         self.question_tag = question_tag
  89.         self.widgets = []
  90.         for choice, tag in choices:
  91.             button = gtk.RadioButton (label=choice)
  92.             if len (self.widgets) > 0:
  93.                 button.set_group (self.widgets[0][0])
  94.             choice_vbox.pack_start (button, False, False, 0)
  95.             self.widgets.append ((button, tag))
  96.  
  97.         troubleshooter.new_page (page, self)
  98.  
  99.     def collect_answer (self):
  100.         for button, answer_tag in self.widgets:
  101.             if button.get_active ():
  102.                 return { self.question_tag: answer_tag }
  103.